package com.suixinsanren.design.compound.demo02;

public class QuackCounter implements QuackAble {

    private final QuackAble quackAble;
    private static int quackCounter = 0;
    private final Observable observable;

    public QuackCounter(QuackAble quackAble) {
        this.quackAble = quackAble;
        this.observable = new Observable(this);
    }

    @Override
    public void quack() {
        quackAble.quack();
        quackCounter++;
        observable.notifyObserver();
    }

    public static int getQuackCounter() {
        return quackCounter;
    }

    @Override
    public void addObserver(Observer observer) {
        observable.addObserver(observer);
    }

    @Override
    public void notifyObserver() {
        observable.notifyObserver();
    }

    @Override
    public String toString() {
        return quackAble.toString();
    }
}
